/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./vTxtInputStream.h"


namespace Vendetta {
	vTxtInputStream::vTxtInputStream() {
	}
	
	vTxtInputStream::~vTxtInputStream() {
	}

	vBool vTxtInputStream::LoadFromFile(const vString& fileName) {
		std::ifstream isFile;
		vString strLine, currentSection = "Default";

		isFile.open(fileName.ToConstCharPtr());
		if (isFile.exceptions() != std::ios_base::goodbit || !isFile.is_open()) {
			throw vException("Can't open file: \"%s\".  In vTxtInputStream::LoadFromFile.", fileName.ToConstCharPtr());
		}

		while (isFile.good()) {
			try {
				GetLine(isFile, strLine);
				postLineLoad(strLine);
			} catch (const vException& e) {
				isFile.close();
				throw e;
			} catch (const vFatalException& fe) {
				isFile.close();
				throw fe;
			}
		}

		isFile.close();

		return true;
	}
}